﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Library;

namespace logic
{
    public class sendEmail
    {
        /// <summary>
        /// 找回密码，通过邮件设置新密码
        /// </summary>
        /// <param name="email">用户Email</param>
        /// <param name="newpwd">随机生成的新密码</param>
        public static void sendNewpwd(string username, string newpwd)
        {
            DataRow dr = customer.getByUsername(username);
            if (dr != null)
            {
                string subject = "想购网密码找回";
                StringBuilder body = new StringBuilder(FileLib.GetTextFromFile(Resource.EmailPath + "mail_getPwd.htm"));
                body.Replace("[#weburl#]", Resource.WebUrl);
                body.Replace("[#webname#]", Resource.WebName);
                body.Replace("[#webmail#]", Resource.WebEmail);
                body.Replace("[#filename#]", "userEditpwd");
                body.Replace("[#username#]", dr["username"].ToString());
                body.Replace("[#password#]", newpwd);
                string to = dr["email"].ToString();
                Email.Send(subject, Resource.WebEmail, Resource.WebEmailPwd, to, body.ToString(), Resource.WebSmtp);
            }
        }
    }
}
